<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>mamma</title>
<link rel="shortcut icon" href="../image/icon_mamma.ico">

<script src="../js/jquery-2.1.1.js"></script>
<script type="text/javascript" src="../js/nicEdit.js"></script> 
<script type="text/javascript">

$(document).ready(function() {
	
	$('#save').on('click', saveform);	
	bkLib.onDomLoaded(function() {
		myNicEditor = new nicEditor(
		{fullPanel : true})
		.panelInstance('infoContent');

		});
});

function saveform() {
	var year = $('#year').val();
	var month = $('#month').val();
	var day = $('#day').val();
	var eyear = $('#eyear').val();
	var emonth = $('#emonth').val();
	var eday = $('#eday').val();
	var infoName = $('#infoName').val();
	
	var nicE = new nicEditors.findEditor('infoContent');
	infoContent = nicE.getContent();
	
	var importance = $('#importance').val();
	
	if (year.length == 0) {
		alert('시작년입력');
		return false;
	}
	if (month.length == 0) {
		alert('시작월입력');
		return false;
	}
	
	if (day.length == 0) {
		alert('시작일입력');
		return false;
	}
	
	if (year.length == 0) {
		alert('종료년입력');
		return false;
	}
	if (month.length == 0) {
		alert('종료월입력');
		return false;
	}
	
	if (day.length == 0) {
		alert('종료일입력');
		return false;
	}
	
	if (infoName.length == 0) {
		alert('제목입력');
		return false;
	}
	
	if (infoContent.length == 0) {
		alert('내용입력');
		return false;
	}
	
	if (year > eyear) {
		alert('종료일을 정확히 입력해 주세요');
		return false;
	}
	
	if(year == eyear){
		if(month > emonth){
		alert('종료일을 정확히 입력해 주세요');
		return false;
		}
	}
	
	if(year == eyear){
		if(month == emonth){
			if(day > eday){
				alert('종료일을 정확히 입력해 주세요');
				return false;
			}
		}
	}
	
	$.ajax({
		url: 'nwrite.action',
		type: 'POST',
		dataType: 'json',
		data: {year:year, month:month, day:day, eyear:eyear, emonth:emonth, eday:eday, importance:importance, infoName:infoName, infoContent: infoContent},
		success: saveOK
	});
	function saveOK() {	
		location.href='../admin/goNoticelistPage.action';
	}
	
}
</script>
</head>
<body topmargin="0"  leftmargin="0" rightmargin="0">
<table id="adhead" border="0" width="100%" height="100px" style="text-align: center;background-color: #EAEAEA;">
<tr>
<td>	
	<a href="../admin/goNoticelistPage.action">공지 관리</a>
	<a href="../admin/goJusalistPage.action">백신 알림</a>
	<a href="../admin/goMemberlistPage.action">회원 목록 보기</a>
	<a href="../admin/goAdBannerPage.action">광고 관리</a>
	<a href="../account/logout.action">로그아웃</a>
</td>
</tr></table>
<h1 style="text-align: center;">[공지 입력]</h1>
<br><br>
<table border=1 style="margin:0 auto;">
<tr>
<th style="text-align: center;background-color: #EAEAEA;">시작날짜</th>
<td>
<select id="year">
			<option selected="selected" value="year"></option>
			<s:iterator var="year" begin="2014" end="2030">
			<option value="${year}">${year}</option>
			</s:iterator>
		</select>년
		<select id="month">
			<option selected="selected" value="month"></option>
			<s:iterator var="month" begin="1" end="12">
			<option value="${month}">${month}</option>
			</s:iterator>
		</select>월
		<select id="day">
			<option selected="selected" value="day"></option>
			<s:iterator var="day" begin="1" end="31">
			<option value="${day}">${day}</option>
			</s:iterator>
		</select>일
</td>
</tr>
<tr>
<th style="text-align: center;background-color: #EAEAEA;">종료날짜</th>
<td>
<select id="eyear">
			<option selected="selected" value="year"></option>
			<s:iterator var="year" begin="2014" end="2030">
			<option value="${year}">${year}</option>
			</s:iterator>
		</select>년
		<select id="emonth">
			<option selected="selected" value="month"></option>
			<s:iterator var="month" begin="1" end="12">
			<option value="${month}">${month}</option>
			</s:iterator>
		</select>월
		<select id="eday">
			<option selected="selected" value="day"></option>
			<s:iterator var="day" begin="1" end="31">
			<option value="${day}">${day}</option>
			</s:iterator>
		</select>일
</td>
</tr>
<tr>
	<th width="100" style="text-align: center;background-color: #EAEAEA;">중요도</th>
	<td>
		<select id="importance">
			<s:iterator status="i" begin="1" end="3">
			<option value="${i.count}">${i.count}</option>
			</s:iterator>
		</select>
	</td>
</tr>

<tr>
	<th width="100" style="text-align: center;background-color: #EAEAEA;">제목</th>
	<td>
		<s:textfield id="infoName" cssStyle="width:800px" theme="simple"/>
	</td>
</tr>
<tr>
	<th width="100" style="text-align: center;background-color: #EAEAEA;">내용</th> 
	<td>
		<s:textarea id="infoContent" cssStyle="width:800px;height:300px;resize:none;" theme="simple" ></s:textarea>
	</td>
</tr>
</table>
<br>
<form style="text-align: center;">
<input type="button" id="save" value="저장" style="width: 100px;">
</form>
</body>
</html>